package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.common.contants.ArticleContants;
import com.heima.model.aritlce.dto.ArticleDto;
import com.heima.model.aritlce.dto.ArticleHomeDto;
import com.heima.model.aritlce.pojo.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(path = "/api/v1/article")
public class ArticleController {

    @Resource
    private  ApArticleService apArticleService;

    @PostMapping(path = "/save")
    @ApiOperation("保存APP端文章数据")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto){
        apArticleService.saveArticle(dto);
        return ResponseResult.success();
    }

    @PostMapping(path = "/load")
    @ApiOperation("首页默认加载推荐频道列表")
    public ResponseResult<List<ApArticle>> load(@RequestBody ArticleHomeDto dto){
        List<ApArticle> articleList = apArticleService.load(dto, ArticleContants.LOAD_TYPE_MORE);
        return ResponseResult.success(articleList);
    }

    @PostMapping(path = "/loadmore")
    @ApiOperation("加载更多文章")
    public ResponseResult<List<ApArticle>> loadmore(@RequestBody ArticleHomeDto dto){
        List<ApArticle> articleList = apArticleService.load(dto, ArticleContants.LOAD_TYPE_MORE);
        return ResponseResult.success(articleList);
    }

    @PostMapping(path = "/loadnew")
    @ApiOperation("加载最最新文章")
    public ResponseResult<List<ApArticle>> loadnew(@RequestBody ArticleHomeDto dto){
        List<ApArticle> articleList = apArticleService.load(dto, ArticleContants.LOAD_TYPE_NEW);
        return ResponseResult.success(articleList);
    }
}
